package com.xjscrm.server.service.filterrule.impl;

import com.xjscrm.common.entity.WwCustomer;
import com.xjscrm.common.utils.Tools;
import com.xjscrm.server.req.filterrule.CustomerBasicInfoExcludeFilterReq;
import com.xjscrm.server.req.filterrule.CustomerFilterRuleReq;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户标签排除过滤器
 */
public class CustomerBasicInfoExcludeFilter extends AbstractCustomerExcludeFilter{

    private CustomerBasicInfoExcludeFilter() {
    }

    private final static CustomerBasicInfoExcludeFilter INSTANCE = new CustomerBasicInfoExcludeFilter();


    /**
     * 根据条件和用户标签进行过滤，排除返回true,否则返回false
     * @param req
     * @return
     */
    @Override
    public Boolean filter(CustomerFilterRuleReq req) {
        CustomerBasicInfoExcludeFilterReq excludeFilterReq = (CustomerBasicInfoExcludeFilterReq) req;
        if (!excludeFilterReq.isOpenExclude()) {
            return false;
        }
        WwCustomer wwCustomer = excludeFilterReq.getWwCustomer();
        if (wwCustomer == null) {
            return true;
        }
        //客户备注选项(0-无备注；1-有备注)
        Integer excludeCustomerRemarkOpt = excludeFilterReq.getExcludeCustomerRemarkOpt();
        //性别(0-未知；1-男；2-女)
        Integer excludeCustomerGenders = excludeFilterReq.getExcludeCustomerGenders();
        if (excludeCustomerRemarkOpt == null && excludeCustomerGenders == null) {
            return false;
        }
        if (excludeCustomerRemarkOpt != null) {
            if (excludeCustomerRemarkOpt.intValue() == 0 && StringUtils.isBlank(wwCustomer.getRemark())) {//无备注
                return true;
            }
            if (excludeCustomerRemarkOpt.intValue() == 1 && StringUtils.isNotBlank(wwCustomer.getRemark())) { //有备注
                return true;
            }
        }
        if (excludeCustomerGenders != null) {
            //验证客户性别是否跟配置的符合
            if (excludeCustomerGenders.intValue() == Tools.getInteger(wwCustomer.getGender()).intValue()) {
                return true;
            }
        }
        return false;

    }

    public static CustomerBasicInfoExcludeFilter getInstance() {
        return INSTANCE;
    }
}
